﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FTBS.Models.DAO;
using FTBS.Models.Entities;

namespace FTBS.Models.BLO
{
    public class UserBLO
    {
        private UserDAO userDAO = new UserDAO();

        /// <summary>
        /// Check login of account and get role
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns>Role Name</returns>
        /// <author>HungPH</author>
        /// <date>3/4/2014</date>
        public String GetRoleNameFromLogin(String username, String password)
        {
            String roleName = "";
            var roleId = userDAO.GetRoleIdFromLogin(username, password);
            if (roleId == 1)
            {
                roleName = "Customer";
            }
            else if (roleId == 2)
            {
                roleName = "Admin";
            }
            else if (roleId == 3)
            {
                roleName = "Staff";
            }
            else if (roleId == 4)
            {
                roleName = "Supplier";
            }
            return roleName;
        }
      
        /// <summary>
        /// display all staffs
        /// </summary>
        /// <returns>list users</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public List<User> DisplayAllStaffs()
        {
            var listStaffs = userDAO.LoadAllStaffs();
            return listStaffs;
        }

        /// <summary>
        /// display all customers
        /// </summary>
        /// <returns></returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public List<User> DisplayAllCustomers()
        {
            var listCustomers = userDAO.LoadAllCustomers();
            return listCustomers;
        }

        /// <summary>
        /// display all ssuppliers
        /// </summary>
        /// <returns>list users</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public List<User> DisplayAllSuppliers()
        {
            var listSuppliers = userDAO.LoadAllSuppliers();
            return listSuppliers;
        }

        /// <summary>
        /// load user by username
        /// </summary>
        /// <param name="username"></param>
        /// <returns>User</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public User LoadUserByUserName(String username)
        {
            return userDAO.LoadUserByUserName(username);
        }

        /// <summary>
        /// Create a staff
        /// </summary>
        /// <param name="user"></param>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public bool CreateStaff(User user)
        {
            var result = userDAO.AddStaff(user);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// Create a supplier
        /// </summary>
        /// <param name="user"></param>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public bool CreateSupplier(User user)
        {
            var result = userDAO.AddSupplier(user);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// edit info staff
        /// </summary>
        /// <param name="user"></param>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public bool EditStaff(User user)
        {
            var result = userDAO.EditStaff(user);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// edit info supplier
        /// </summary>
        /// <param name="user"></param>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public bool EditSupplier(User user)
        {
            var result = userDAO.EditSupplier(user);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// active user
        /// </summary>
        /// <param name="user"></param>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public bool ActiveUser(User user)
        {
            var result = userDAO.ActiveUser(user);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// deactive user
        /// </summary>
        /// <param name="user"></param>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public bool DeactiveUser(User user)
        {
            var result = userDAO.DeactiveUser(user);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// delete user
        /// </summary>
        /// <param name="user"></param>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public bool DeleteUser(User user)
        {
            var result = userDAO.Delete(user);
            if (result == 1)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// check existed user
        /// </summary>
        /// <param name="user"></param>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public bool CheckUsername(User user)
        {
            var result = userDAO.CheckIsExisted(user);
            return result;
        }

        /// <summary>
        /// check existed email
        /// </summary>
        /// <param name="user"></param>
        /// <returns>success: true; fail: false</returns>
        /// <author>hungph</author>
        /// <date>3/8/2014</date>
        public bool CheckEmail(User user)
        {
            var result = userDAO.CheckEmail(user);
            return result;
        }
    }
}